import java.io.FileWriter;
import java.io.IOException;
import java.util.Random;

public class MathExercisesGenerator {
    public static void main(String[] args) {
        int totalExercises = 100; // 总共生成100个习题
        Random random = new Random();
        try (FileWriter writer = new FileWriter("MathExercises.csv")) {
            writer.write("Expression,Result\n"); // CSV文件的标题行

            for (int i = 0; i < totalExercises; i++) {
                int num1 = random.nextInt(101); // 随机生成0到100的整数
                int num2 = random.nextInt(101); // 随机生成0到100的整数
                char operation = random.nextBoolean() ? '+' : '-'; // 随机选择加法或减法
                int result = operation == '+' ? num1 + num2 : num1 - num2;

                // 写入CSV文件
                writer.write(String.format("%d %c %d,%d\n", num1, operation, num2, result));
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}